// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-11-30

#ifndef __TM_USERACTIVE_H_COMMON_SVR_BASE__
#define __TM_USERACTIVE_H_COMMON_SVR_BASE__

#pragma once

#include "base_timer.h"
#include "svr_asyncobj.h"

namespace JoyServer
{

class CJoyUser;
class CJoyUserSet;
class CJoyServer;
class CJoyAsyncQueue;
class CJoyTmUserActive;

static const int JOY_ACTIVE_MAX = 64;

class CJoyUserActiveUpdate : public CJoyAsyncObject
{
public:
    struct CUserInfo
    {
        UINT    userId;
        UINT    tempId;
    };
    CUserInfo m_userInfos[JOY_ACTIVE_MAX];
    CJoyUserSet* m_userSets[JOY_ACTIVE_MAX];

    int m_infoCount;
    CJoyServer* m_server;

    virtual void OnExecute();
    CJoyUserActiveUpdate(CJoyTmUserActive*);
};

// update user active time in online table.
class CJoyTmUserActive : public CJoyTimerObject
{
protected:
    friend class CJoyUserActiveUpdate;

    CJoyAsyncQueue* m_asyncQueue;
    int m_userSetIndex;
    DWORD m_configElapse;

    virtual CJoyUserActiveUpdate* AllocUpdateObj();
    virtual CJoyAsyncQueue* AllocAsyncQueue();

    virtual void OnExecute();
    virtual void OnUserActiveBegin();
    virtual void OnUserActive(CJoyUser* pUser);
    virtual void OnUserActiveEnd();
public:
    CJoyServer* m_server;
public:
    CJoyTmUserActive();
    virtual ~CJoyTmUserActive();

    virtual bool Create(CJoyServer* pServer);
    virtual void Destroy();
};


} // namespace JoyServer

#endif  // __TM_USERACTIVE_H_COMMON_SVR_BASE__